package com.wzp.Service.impl;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wzp.Dao.StandardMapper;
import com.wzp.PO.Paging;
import com.wzp.PO.comment;
import com.wzp.PO.loginRecord;
import com.wzp.PO.user;
import com.wzp.Service.StandardService;

@Service
public class StandardServiceImpl implements StandardService {

	@Resource
	private StandardMapper mapper;
	
	

	@Override
	public int selectuser(user param) throws Exception {
		return mapper.selectuser(param);
	}

	@Override
	public int adduser(user param) throws Exception {
		
		try {
			mapper.adduser(param);
			return 0;
		} catch (Exception e) {
			System.out.println("注册用户失败");
			return 1;
		}
	}

	@Override
	public int queryUserByname(user param) throws Exception {

		return mapper.queryUserByname(param);
	}

	/*@Override
	public List<DepartmentPO> queryDepartment() throws Exception {

		return mapper.queryDepartment();
	}

	@Override
	public List<DepartmentType> queryDepartmentType() throws Exception {
		
		return mapper.queryDepartmentType();
	}*/

	@Override
	public List<comment> queryComment(Paging param) throws Exception {
		
			
		return mapper.queryComment(param);
	}

	@Override
	public void addComment(comment param) throws Exception {
		mapper.addComment(param);
	}

	@Override
	public user queryUser(user param) throws Exception {
		return mapper.queryUser(param);
	}

	@Override
	public void addloginRecord(loginRecord param) throws Exception {
		
		param.setLoginTime(new Timestamp(System.currentTimeMillis()));
		mapper.addloginRecord(param);
	}

	@Override
	public int queryRowsByTableName(String param) throws Exception {
		
		return mapper.queryRowsByTableName(param);
	}

	@Override
	public Paging PagingComment(Paging param) throws Exception {
		
		int totalRecords = mapper.queryRowsByTableName("wzpbk.comment");
		
		int totalPage = totalRecords/param.getRows();
		if(totalRecords%param.getRows()!=0){
			totalPage = totalPage+1;
		}
		
		Paging paging = new Paging();
		
		paging.setData(queryComment(param));
		paging.setTotalPage(totalPage);
		paging.setRows(param.getRows());
		paging.setTotalRecords(totalRecords);
		return paging;
	}

}
